<?php

namespace app\controller;

use app\BaseController;
use app\service\Atomic;
use Swoole\Server;
use think\App;
use think\facade\Queue;

class Index extends BaseController
{
    public function index(App $app, Atomic $atomic, Server $server)
    {
        if ($this->request->param('to')) {
            //接口投递消息
            $event = event('swoole.websocket.Point', ['api' => true, 'uid' => $this->request->param('uid'), 'to' => $this->request->param('to'), 'content' => $this->request->param('msg')]);
            dump($event);
        }
        if ($this->request->param('app')) {
            dump($app);
        }
        if ($this->request->param('vote')) {
            $atomic->add((string)rand(1, 5));
            $atomic->add((string)rand(1, 5), 2);
            $atomic->add((string)rand(1, 5), rand(1, 10));
            dump($atomic->all());
        }
        if ($this->request->param('task')) {
            $server->task(['time' => time()]);
            $server->task(['cmd' => 'order', 'time' => time()]);
        }
        if ($this->request->param('job')) {
            dump(Queue::push(config('job.job1'), ['push' => time()]));
            //延迟任务
            dump(Queue::later(5, config('job.job1'), ['push' => time()]));
        }
        echo 'think-swoole demo.';
    }
}
